/*
 * E.cxx
 *
 *  Created on: 4:38:05 PM Oct 14, 2012
 *  Author: Pallab
 *
 * "I have not failed, I have just found 10000 ways that won't work.
*/

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define lines puts("")

inline void wait(double seconds) {
	double endtime = clock() + (seconds * CLOCKS_PER_SEC);
	while (clock() < endtime) {
		;
	}
}
#define T int
inline T fastIn() {
	register char c = 0;
	register T a = 0;
	while (c < 33)
		c = getchar();
	while (c > 33) {
		a = (a * 10) + (c - '0');
		c = getchar();
	}
	return a;
}
int word_count;
string words[1000 + 5];
char buff[1000005];
inline void read() {
	scanf("%d\n", &word_count);
	fo(i,word_count){
		gets(buff);
		words[i] = (string) buff;
	}
}
struct NODE {
	int point_to;
	int freq;
	int length;
	NODE(int point_to = 0, int freq = 0, int length = 0) :
			point_to(point_to), freq(freq), length(length) {
		;
	}
};

const int MX = 1000010;
map<char, NODE> t[MX];
int root;
int sum;
inline void ini() {
	fo(i,MX)
		t[i].clear();
	root = 0;
}
inline void go(string &s) {
	int now = 0;
	fo(i,LN(s)){
		char c = s[i];
		//jodi c character'ta current node'a already thake
		map<char, NODE> &tmp = t[now];
		if (tmp.count(c)) {
			now = tmp[c].point_to;
			tmp[c].freq++;
			tmp[c].length = i;
		} else {
			//jodi current character'ta current node a na thake
			now = ++root;
			tmp[c] = NODE(now, 1, i);
		}
	}
}

void dfs(int u) {
	for (char c = 'a'; c <= 'z'; ++c) {
		map<char, NODE> &tmp = t[u];
		if (tmp.count(c)) {
			if (tmp[c].freq == 1) {
				sum += (tmp[c].length + 1);
			} else {
				dfs(tmp[c].point_to);
			}
		}
	}
}
inline void proc() {
	ini();
	fo(i,word_count)
		go(words[i]);

	sum = 0;
	dfs(0);
	cout << sum << '\n';
}
int main() {
	int kase = 1;
#if defined( xerxes_pc )
	if (!freopen("E/in1", "r", stdin))
		puts("error opening file E/in1 "), assert(0);
	kase = 1;
#endif
	scanf("%d", &kase);
	fo(i,kase)
	{
		read();
		proc();
	}
	return 0;
}


